<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    </script>
</head>

<body>
    <div id="app">
        <div>
            <input type="checkbox" @change="allChange" v-model="isAllChecked"> 全选
        </div>
        <ul>
            <li v-for="item in list" :key="item.id">
                <input type="checkbox" @change="itemChange" :value="item" v-model="checkGroup">
                <span>{{item}}</span>

                <span>
                    
                    <button v-if="item.num>1" @click="item.num--">del</button>
                    <button v-else  >del</button>
                    {{item.num}}
                    <button @click="item.num++">add</button>
                </span>
            </li>
        </ul>
        <div>合计：{{totalPrice}}</div>
        <div>{{checkGroup}}</div>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                list: [{
                    name: "商品1",
                    price: 10,
                    num: 2,
                    id: 1
                }, {
                    name: "商品2",
                    price: 100,
                    num: 10,
                    id: 2
                }, {
                    name: "商品3",
                    price: 10,
                    num: 2,
                    id: 3
                }],
                checkGroup: [],
                isAllChecked: false
            },
            computed: {
                totalPrice() {
                    return this.checkGroup.reduce(function(prev, curr, idx, arr) {
                        return curr.price * curr.num + prev;
                    }, 0);
                }
            },
            methods: {
                allChange() {
                    if (this.isAllChecked) {
                        this.checkGroup = [...this.list]
                    } else {
                        this.checkGroup = []
                    }
                },
                itemChange() {
                    this.isAllChecked = this.list.length === this.checkGroup.length
                }
            },
        })
    </script>
</body>

</html>